{{Extend "db/redis/layout"}}
{{Block "title"}}{{"数据库"|T}}: {{Stored.dbName}} - {{Super}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li><a href="{{dbMgrURL "listTable" Stored.dbName}}" data-pjax="#pcont" data-keepjs="true">{{"数据库"|T}}: {{Stored.dbName}}</a></li>
<li class="active">Key: {{Stored.table}}</li>
{{/Block}}
{{Block "main"}}
{{$table := Stored.table}}
<div class="row">
    <div class="col-md-12">
        <div class="block-flat">
          <div class="header">
            <div class="btn-group pull-right">
			<a href="{{dbMgrURL "createTable" Stored.dbName}}" class="btn btn-success" data-pjax="#pcont" data-keepjs="true">
				<i class="fa fa-plus"></i>
				{{"添加"|T}}
			</a>
			<a href="{{dbMgrURL "modifyTable" Stored.dbName $table}}" class="btn btn-primary" data-pjax="#pcont" data-keepjs="true">
				<i class="fa fa-pencil"></i>
				{{"修改"|T}}
			</a>
			<a href="javascript:;" id="delete-key" class="btn btn-danger">
				<i class="fa fa-times"></i>
				{{"删除"|T}}
			</a>
            </div>
            <h3>Key: {{$table}}</h3>
          </div>
          <div class="content">
             <div class="table-responsive">
				<table class="table no-border hover blue">
                    <colgroup>
                        <col width="100px" />
                        <col />
                    </colgroup>
                    {{$dataType := Stored.dataType}}
					<tbody class="no-border-x" id="tbody-content">
                        <tr>
                            <td><strong>Type</strong></td>
                            <td>{{$dataType}}</td>
                        </tr>
                        <tr>
                            <td><strong>TTL</strong></td>
                            <td>{{Stored.ttl}}</td>
                        </tr>
                        <tr>
                            <td><strong>Encoding</strong></td>
                            <td>{{Stored.encoding}}</td>
                        </tr>
                        <tr>
                            <td><strong>Size</strong></td>
                            <td>{{Stored.result.TotalRows}}</td>
                        </tr>
                        <tr>
                            <td colspan="2">
                            {{if eq $dataType "list"}}
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>Index</th>
                                        <th>Value</th>
                                        <th style="width:80px">{{"操作"|T}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                {{range $index,$value:=Stored.result.List}}
                                    <tr class="value-row">
                                        <td>{{$index}}</td>
                                        <td>{{$value}}</td>
                                        <td>
                                            <a class="label label-success" data-toggle="tooltip" title="{{"修改"|T}}" href="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&index={{$index}}&operate=editValue"><i class="fa fa-pencil"></i></a> 
                                            <a class="label label-danger" data-toggle="tooltip" title="{{"删除"|T}}" href="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&index={{$index}}&operate=deleteValue" onclick="return confirm('{{"真的要删除吗？"|T}}');"><i class="fa fa-times"></i></a>
                                        </td>
                                    </tr>
                                {{end}}
                                </tbody>
                            </table>
                            {{Stored.result.Paging.Render "pagination_cursor"}}
                            {{else if eq $dataType "hash"}}
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>Key</th>
                                        <th>Value</th>
                                        <th style="width:80px">{{"操作"|T}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                {{range $index,$key:=Stored.result.Keys}}
                                    <tr class="value-row">
                                        <td>{{$key}}</td>
                                        <td>{{Stored.result.Value $index}}</td>
                                        <td>
                                            <a class="label label-success" data-toggle="tooltip" title="{{"修改"|T}}" href="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&hkey={{$key}}&operate=editValue"><i class="fa fa-pencil"></i></a> 
                                            <a class="label label-danger" data-toggle="tooltip" title="{{"删除"|T}}" href="javascript:;" data-del-url="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&hkey={{$key}}&operate=deleteValue"><i class="fa fa-times"></i></a>
                                        </td>
                                    </tr>
                                {{end}}
                                </tbody>
                            </table>
                            {{Stored.result.CursorPaging.Render "pagination_cursor"}}
                            {{else if eq $dataType "set"}}
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>Value</th>
                                        <th style="width:80px">{{"操作"|T}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                {{range $index,$value:=Stored.result.List}}
                                    <tr class="value-row">
                                        <td>{{$value}}</td>
                                        <td>
                                            <a class="label label-success" data-toggle="tooltip" title="{{"修改"|T}}" href="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&value={{$value}}&operate=editValue"><i class="fa fa-pencil"></i></a> 
                                            <a class="label label-danger" data-toggle="tooltip" title="{{"删除"|T}}" href="javascript:;" data-del-url="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&value={{$value}}&operate=deleteValue"><i class="fa fa-times"></i></a>
                                        </td>
                                    </tr>
                                {{end}}
                                </tbody>
                            </table>
                            {{Stored.result.CursorPaging.Render "pagination_cursor"}}
                            {{else if eq $dataType "zset"}}
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>Score</th>
                                        <th>Value</th>
                                        <th style="width:80px">{{"操作"|T}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                {{range $index,$score:=Stored.result.Keys}}
                                    <tr class="value-row">{{$value:=Stored.result.Value $index}}
                                        <td>{{$score}}</td>
                                        <td>{{$value}}</td>
                                        <td>
                                            <a class="label label-success" data-toggle="tooltip" title="{{"修改"|T}}" href="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&value={{$value}}&operate=editValue&score={{$score}}"><i class="fa fa-pencil"></i></a> 
                                            <a class="label label-danger" data-toggle="tooltip" title="{{"删除"|T}}" href="javascript:;" data-del-url="{{dbMgrURL "modifyTable" Stored.dbName $table}}&key={{Stored.table}}&value={{$value}}&operate=deleteValue"><i class="fa fa-times"></i></a>
                                        </td>
                                    </tr>
                                {{end}}
                                </tbody>
                            </table>
                            {{Stored.result.CursorPaging.Render "pagination_cursor"}}
                            {{else}}
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>Value</th>
                                        <th style="width:80px">{{"操作"|T}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr class="value-row">
                                        <td>{{Stored.result}}</td>
                                        <td>
                                            <a class="label label-success" data-toggle="tooltip" title="{{"修改"|T}}" href="{{dbMgrURL "modifyTable" Stored.dbName $table}}&&key={{Stored.table}}&operate=editValue"><i class="fa fa-pencil"></i></a> 
                                            <a class="label label-danger" data-toggle="tooltip" title="{{"删除"|T}}" href="javascript:;" data-del-url="{{dbMgrURL "modifyTable" Stored.dbName $table}}&&key={{Stored.table}}&operate=deleteValue"><i class="fa fa-times"></i></a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            {{end}}
                            </td>
                        </tr>
					</tbody>
				</table>		
			    </div>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->

    </div>
</div>
{{/Block}}

{{Block "footer"}}
{{Super}}
{{$table := Stored.table}}
<script>
$(function(){
    $('#delete-key').off().on('click',function(r){
        if(!confirm('{{T "确定要删除“%s”吗？" $table}}')) return;
        $.get('{{dbMgrURL "modifyTable" Stored.dbName $table}}',{key:'{$table}',operate:'delete'},function(r){
            if(r.Code==1){
              window.setTimeout(function(){
                window.location='{{dbMgrURL "info"}}';
              },3000);
            }
			App.message({text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
        },'json');
    });
    $('#tbody-content a[data-del-url]').off().on('click',function(e){
        if(!confirm('{{"真的要删除吗？"|T}}')) return;
        var that=$(this);
        $.get(that.data('del-url'),{},function(r){
            if(r.Code==1){
                alert(that.parents('tr.value-row').html())
                that.parents('tr.value-row').remove();
            }
			App.message({text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
        },'json');
    });
});
</script>
{{/Block}}